package com.gg.fmallspringboot.service.impl;

import com.gg.fmallspringboot.entity.ShoppingCart;
import com.gg.fmallspringboot.mapper.CarMapper;
import com.gg.fmallspringboot.model.Result;
import com.gg.fmallspringboot.service.CarService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 购物车CarServiceImpl
 */
@Service
public class CarServiceImpl implements CarService {

    private CarMapper carMapper;

    public CarServiceImpl(CarMapper carMapper) {
        this.carMapper = carMapper;
    }

    @Override
    public List<ShoppingCart> carList() {
        return carMapper.selectShop();
    }

    @Override
    public Result getOrderCar(String carIds,Integer userId) {
        String[] split = carIds.split(",");
        List<String> list = Arrays.asList(split);
        List<ShoppingCart> orderCar = carMapper.getOrderCar(list, userId);
        Result result;
        if (orderCar==null){
            result = new Result(1,"查询失败");
        }else {
            result = new Result(0,"查询成功",orderCar);
        }
        return result;
    }
}
